"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameHttpHelper = void 0;
const DateUtil_1 = require("../../engine/utils/DateUtil");
const HttpUtil_1 = require("../../engine/utils/HttpUtil");
const Logger_1 = require("../../engine/utils/Logger");
const request = require('request');
class GameHttpHelper {
    static init() {
        // if (Config.environment == Config.EnvironmentType.yueyouhui) {
        //     this.Game_url = "http://127.0.0.1:9231"
        // }
        // else if (Config.environment == Config.EnvironmentType.xj) {
        //     this.Game_url = "http://127.0.0.1:9231"
        // }
        // else if (Config.environment == Config.EnvironmentType.Jk) {
        //     this.Game_url = "http://127.0.0.1:9235"
        // }
        // else if (Config.environment == Config.EnvironmentType.chaoyou) {
        //     this.Game_url = "http://127.0.0.1:9233"
        // }
        // else {
        this.Game_url = "http://127.0.0.1:9236";
        // }
    }
    static get_online_num(url) {
        return new Promise((resolve, reject) => {
            HttpUtil_1.HttpUtil.request_by_body(url, {}, (response) => {
                if (response["status"] == 200) {
                    resolve(response["data"]);
                }
            });
        });
    }
    static onlinenum() {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "admin",
                "func": "onlinenum",
            };
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("onlinenum==resp==", res);
            return res["data"];
        });
    }
    static charge_by_gm(id, num, mod = "gem") {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": mod,
                "func": "add",
                "rid": id,
                "num": num,
            };
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("charge_by_gm==resp==", res);
            return res["data"];
        });
    }
    // http://127.0.0.1:9230?mod=result&func=change&r1=1&r2=1&operator=acc&tableid=1
    static yuxiaxie_control(touzi1, touzi2, operator, tableid) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "result",
                "func": "change",
                "r1": touzi1,
                "r2": touzi2,
                "operator": operator,
                "tableid": tableid,
            };
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("yuxiaxie_control==resp==", res);
            return res["data"];
        });
    }
    static group_list() {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "log",
                "func": "groupList",
            };
            Logger_1.Logger.log("group_list==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("group_list==resp==", res);
            return res["data"];
        });
    }
    static group_member(groupid) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "log",
                "func": "groupMemberList",
                "groupid": groupid,
            };
            Logger_1.Logger.log("group_member==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("group_member==resp==", res);
            return res["data"];
        });
    }
    static groupTableList(groupid) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "log",
                "func": "groupTableList",
                "groupid": groupid,
            };
            Logger_1.Logger.log("groupTableList==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("groupTableList==resp==", res);
            return res["data"];
        });
    }
    static groupZhanji(groupid, time) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "log",
                "func": "groupZhanji",
                "groupid": groupid,
                "time": time,
            };
            Logger_1.Logger.log("groupZhanji==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("groupZhanji==resp==", res);
            return res["data"];
        });
    }
    static groupZhanjiOne(groupid, time, userid) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "log",
                "func": "groupZhanjiOne",
                "groupid": groupid,
                "time1": time,
                "time2": Math.floor(DateUtil_1.default.now() / 1000),
                "userid": userid,
            };
            Logger_1.Logger.log("groupZhanjiOne==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("groupZhanjiOne==resp==", res);
            return res["data"];
        });
    }
    static groupDiss(groupid) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "log",
                "func": "groupDiss",
                "groupid": groupid,
            };
            Logger_1.Logger.log("groupDiss==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("groupDiss==resp==", res);
            return res["data"];
        });
    }
    static robot_list() {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "robot2",
                "func": "list",
            };
            Logger_1.Logger.log("robot_list==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("robot_list==resp==", res);
            return res["data"];
        });
    }
    static robot_create(groupid, nick, face, time, robotid, min, max, tableid) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "robot2",
                "func": "create",
                "groupid": groupid,
                "nick": nick,
                "face": face,
                "time": time,
                "robotid": robotid,
                "min": min,
                "max": max,
                "tableid": tableid,
            };
            if (robotid > 0) {
                data["func"] = "edit";
            }
            Logger_1.Logger.log("robot_create==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("robot_create==resp==", res);
            return res["data"];
        });
    }
    static robot_apply(robotid) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "robot2",
                "func": "apply",
                "robotid": robotid,
            };
            Logger_1.Logger.log("robot_apply==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("robot_apply==resp==", res);
            return res["data"];
        });
    }
    static robot_leave(robotid) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "robot2",
                "func": "leave",
                "robotid": robotid,
            };
            Logger_1.Logger.log("robot_leave==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("robot_leave==resp==", res);
            return res["data"];
        });
    }
    static getWaigua_list() {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "result",
                "func": "white_list",
            };
            Logger_1.Logger.log("getWaigua_list==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("getWaigua_list==resp==", res);
            return res["data"];
        });
    }
    static set_waigua_list(udis) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "result",
                "func": "add_white",
                "uids": udis
            };
            Logger_1.Logger.log("set_waigua_list==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("set_waigua_list==resp==", res);
            return res["data"];
        });
    }
    static set_yuxiaxie_rate(tableid, rate, operator) {
        return __awaiter(this, void 0, void 0, function* () {
            let data = {
                "mod": "result",
                "func": "rate",
                "operator": operator,
                "tableid": tableid,
                "rate": rate
            };
            Logger_1.Logger.log("set_yuxiaxie_rate==req==", data);
            let res = yield HttpUtil_1.HttpUtil.request_by_form_promise(this.Game_url, data);
            Logger_1.Logger.log("set_yuxiaxie_rate==resp==", res);
            return res["data"];
        });
    }
}
exports.GameHttpHelper = GameHttpHelper;
GameHttpHelper.Game_url = "http://127.0.0.1:9230";
